<script type="text/javascript">
  function appScaleApply(){
    var appId = $('#appScale_appId').selectpicker('val');
    if (appId == null || appId == '') {
      alert("请选择应用");
      $('#appScale_appId').focus();
      return false;
    }

    var applyMemSize = document.getElementById("applyMemSize");
    if(applyMemSize.value == ""){
      alert("请填写要扩容的容量!");
      applyMemSize.focus();
      return false;
    }

    var appScaleReason = document.getElementById("appScaleReason");
    if(appScaleReason.value == ""){
      alert("请填写申请扩容的原因!");
      appScaleReason.focus();
      return false;
    }
    var appScaleApplyBtn = document.getElementById("appScaleApplyBtn");
    appScaleApplyBtn.disabled = true;

    $.post(
            '${request.contextPath}/admin/app/scale',
            {
              appId: appId,
              applyMemSize: applyMemSize.value,
              appScaleReason: appScaleReason.value
            },
            function(data){
              if (data == 1) {
                $("#appScaleApplyInfo").html("<div class='alert alert-error' ><font color='green'><strong>Success!</strong>容量变更申请提交成功，即将跳转工单列表！</font><button class='btn-close' data-bs-dismiss='alert'></button></div>");
                setTimeout("location.href = '${request.contextPath}/admin/app/jobs'", 1000);
              } else {
                btn.disabled = false;
                $("#appScaleApplyInfo").html("<div class='alert alert-error' ><font color='red'><strong>Error!</strong>更新失败！<font><button class='btn-close' data-bs-dismiss='alert'></button></div>");
              }
            }
    );
  }
</script>

<div class="card-header">
  <h4 class="card-title">
    扩容/缩容
  </h4>
</div>

<div class="card-body">
    <div class="row">
      <div class="form-group row">
        <label class="col-form-label col-md-2 offset-md-1">应用<font color='red'>(*)</font></label>
        <div class="col-md-5">
          <select id="appScale_appId" name="appId" class="selectpicker show-tick col-md-12 border rounded"
                  data-live-search="true" title="选择应用">
            <option value="">选择应用</option>
            <#list appDescMap?keys as key>
              <#assign appDesc = appDescMap?api.get(key)>
              <#if (appDesc.status==2)>
                <option value="${appDesc.appId}" title="${appDesc.appId} ${appDesc.name}" <#if (appId?? && appId == appDesc.appId)>selected="selected"</#if>>
                    【${appDesc.appId}】&nbsp;名称：${appDesc.name}&nbsp;类型：${appDesc.typeDesc}&nbsp;版本：${appDesc.versionName}
                </option>
              </#if>
            </#list>
          </select>
        </div>
      </div>

      <div class="form-group row">
        <label class="col-form-label col-md-2 offset-md-1">应用容量<font color='red'>(*)</font></label>
        <div class="col-md-5">
          <input type="text" name="applyMemSize" id="applyMemSize" value="2G" class="form-control"/>
          <span class="help-block">请填写变更后的应用总容量</span>
          <span class="help-block">如：256M,512M,1G..20G</span>
        </div>
      </div>

      <div class="form-group row">
        <label class="col-form-label col-md-2 offset-md-1">申请原因<font color='red'>(*)</font></label>
        <div class="col-md-5">
          <textarea rows="5" name="appScaleReason" id="appScaleReason" placeholder="申请扩容原因" class="form-control"></textarea>
        </div>
        </div>
      </div>

      <div class="form-group row">
        <div class="text-center">
          <button id="appScaleApplyBtn" class="btn btn-info" onclick="appScaleApply()">
            <i class="bi bi-check"></i>
            提交申请
          </button>
        </div>
      </div>

      <div class="form-group row">
        <div id="appScaleApplyInfo" class="offset-md-3 col-md-9"></div>
      </div>
    </div>

</div>
